<!DOCTYPE html>




<html class="theme-next gemini" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.3" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.3">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.3">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.3">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.3" color="#222">





  <meta name="keywords" content="MongoDB,Java MongoDB," />





  <link rel="alternate" href="/atom.xml" title="流水不腐小夏" type="application/atom+xml" />






<meta name="description" content="浅谈MongoDB数据库   浅谈MongoDB数据库 简介 MongoDB 介绍 数据库安装   MongoDB使用 MongoDB可视化工具   Java操作MongoDB 总结 相关资料     简介最近项目中需要分析Http报文，并且需要用数据库保存，刚刚开始打算用Mysql，后来咨询了老司机，老司机建议使用MongoDB来实现，所以特写一篇文章来总结下。 MongoDB 介绍 Mongo">
<meta name="keywords" content="MongoDB,Java MongoDB">
<meta property="og:type" content="article">
<meta property="og:title" content="浅谈MongoDB数据库">
<meta property="og:url" content="http://mycommons.cn/2017/09/28/MongoDb/index.html">
<meta property="og:site_name" content="流水不腐小夏">
<meta property="og:description" content="浅谈MongoDB数据库   浅谈MongoDB数据库 简介 MongoDB 介绍 数据库安装   MongoDB使用 MongoDB可视化工具   Java操作MongoDB 总结 相关资料     简介最近项目中需要分析Http报文，并且需要用数据库保存，刚刚开始打算用Mysql，后来咨询了老司机，老司机建议使用MongoDB来实现，所以特写一篇文章来总结下。 MongoDB 介绍 Mongo">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/1520343-acd14283311d877c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/1520343-2988a2e07e9d3743.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:updated_time" content="2017-10-25T11:47:24.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="浅谈MongoDB数据库">
<meta name="twitter:description" content="浅谈MongoDB数据库   浅谈MongoDB数据库 简介 MongoDB 介绍 数据库安装   MongoDB使用 MongoDB可视化工具   Java操作MongoDB 总结 相关资料     简介最近项目中需要分析Http报文，并且需要用数据库保存，刚刚开始打算用Mysql，后来咨询了老司机，老司机建议使用MongoDB来实现，所以特写一篇文章来总结下。 MongoDB 介绍 Mongo">
<meta name="twitter:image" content="http://upload-images.jianshu.io/upload_images/1520343-acd14283311d877c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.3',
    sidebar: {"position":"left","display":"always","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":false,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: 'GRLHBBCD9E',
      apiKey: '759ab3f5c09b132b3ed4842a44c53c45',
      indexName: 'mycommons',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://mycommons.cn/2017/09/28/MongoDb/"/>





  <title>浅谈MongoDB数据库 | 流水不腐小夏</title>
  





  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?55458ffca1f60dd283f11b9a7f82b262";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">流水不腐小夏</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <h1 class="site-subtitle" itemprop="description">http://mycommons.cn</h1>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-commonweal">
          <a href="/404.html" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-heartbeat"></i> <br />
            
            公益404
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  
  <div class="algolia-popup popup search-popup">
    <div class="algolia-search">
      <div class="algolia-search-input-icon">
        <i class="fa fa-search"></i>
      </div>
      <div class="algolia-search-input" id="algolia-search-input"></div>
    </div>

    <div class="algolia-results">
      <div id="algolia-stats"></div>
      <div id="algolia-hits"></div>
      <div id="algolia-pagination" class="algolia-pagination"></div>
    </div>

    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
  </div>




    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://mycommons.cn/2017/09/28/MongoDb/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="流水不腐小夏">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.jpeg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="流水不腐小夏">
    </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">浅谈MongoDB数据库</h2>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-09-28T18:39:17+08:00">
                2017-09-28
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/数据库/" itemprop="url" rel="index">
                    <span itemprop="name">数据库</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2017/09/28/MongoDb/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count disqus-comment-count"
                        data-disqus-identifier="2017/09/28/MongoDb/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          

          
            <span class="post-meta-divider">|</span>
            <span class="page-pv">本文总阅读量
            <span class="busuanzi-value" id="busuanzi_value_page_pv" ></span>次
            </span>
          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h1 id="浅谈MongoDB数据库"><a href="#浅谈MongoDB数据库" class="headerlink" title="浅谈MongoDB数据库"></a>浅谈MongoDB数据库</h1><hr>
<!-- TOC -->
<ul>
<li><a href="#浅谈mongodb数据库">浅谈MongoDB数据库</a><ul>
<li><a href="#简介">简介</a></li>
<li><a href="#mongodb-介绍">MongoDB 介绍</a><ul>
<li><a href="#数据库安装">数据库安装</a></li>
</ul>
</li>
<li><a href="#mongodb使用">MongoDB使用</a><ul>
<li><a href="#mongodb可视化工具">MongoDB可视化工具</a></li>
</ul>
</li>
<li><a href="#java操作mongodb">Java操作MongoDB</a></li>
<li><a href="#总结">总结</a></li>
<li><a href="#相关资料">相关资料</a></li>
</ul>
</li>
</ul>
<!-- /TOC -->
<h2 id="简介"><a href="#简介" class="headerlink" title="简介"></a>简介</h2><p>最近项目中需要分析Http报文，并且需要用数据库保存，刚刚开始打算用Mysql，后来咨询了老司机，老司机建议使用MongoDB来实现，所以特写一篇文章来总结下。</p>
<h2 id="MongoDB-介绍"><a href="#MongoDB-介绍" class="headerlink" title="MongoDB 介绍"></a>MongoDB 介绍</h2><blockquote>
<p>MongoDB是一个介于关系数据库和非关系数据库之间的产品，是非关系数据库当中功能最丰富，最像关系数据库的。它支持的数据结构非常松散，是类似json的bson格式，因此可以存储比较复杂的数据类型。Mongo最大的特点是它支持的查询语言非常强大，其语法有点类似于面向对象的查询语言，几乎可以实现类似关系数据库单表查询的绝大部分功能，而且还支持对数据建立索引。</p>
</blockquote>
<p>上面是百度百科的介绍，这里是MongoDB的<a href="https://www.mongodb.com/" target="_blank" rel="external">官网</a>。</p>
<p>简单来说MongoDB是一种数据库，不过是非关系型数据库，它的一些概念和数据库不太一样。</p>
<p>MongoDB中一些概念和普通数据库不太一样，普通数据库有database、table、row、field的概念，MongoDB依次叫database、collection、document、field，这个在后面的代码示例会有体现。</p>
<h3 id="数据库安装"><a href="#数据库安装" class="headerlink" title="数据库安装"></a>数据库安装</h3><p>因为用的是Mac，简单介绍下MongoDB在Mac上面的安装，Windows用户可以参考官网。</p>
<p>Mac上安装，直接使用Homebrew就可以了，如果不清楚Homebrew是什么，可以参考<a href="https://brew.sh/" target="_blank" rel="external">这里</a>。</p>
<p>brew 安装MongoDB</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">brew install mongodb</div></pre></td></tr></table></figure>
<p>结果如下</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div></pre></td><td class="code"><pre><div class="line">$ brew install mongodb</div><div class="line">Updating Homebrew...</div><div class="line">==&gt; Downloading https://homebrew.bintray.com/bottles/mongodb-3.4.9.sierra.bottle.tar.gz</div><div class="line"><span class="comment">######################################################################## 100.0%</span></div><div class="line">==&gt; Pouring mongodb-3.4.9.sierra.bottle.tar.gz</div><div class="line">==&gt; Caveats</div><div class="line">To have launchd start mongodb now and restart at login:</div><div class="line">  brew services start mongodb</div><div class="line">Or, <span class="keyword">if</span> you don<span class="string">'t want/need a background service you can just run:</span></div><div class="line"><span class="string">  mongod --config /usr/local/etc/mongod.conf</span></div><div class="line"><span class="string">==&gt; Summary</span></div><div class="line"><span class="string">🍺  /usr/local/Cellar/mongodb/3.4.9: 19 files, 284.9MB</span></div></pre></td></tr></table></figure>
<p>上面给的信息说明很清楚，如果当做一个服务器来用，直接用<code>brew services start mongodb</code>就行了，如果只是作为一个程序，那么用<code>mongod --config /usr/local/etc/mongod.conf</code>启动，<code>/usr/local/etc/mongod.conf</code>是默认配置文件。</p>
<p>我们可以看下配置文件内容，分别是日志路径、存储路径。最后一个是IP访问设置，默认只能本地访问，如果其他机器需要访问这个数据库，需要在配置文件中添加对应的IP。假如想省事，可以设置为<code>0.0.0.0</code>，那么任意机器都是可以访问的。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">$ cat /usr/<span class="built_in">local</span>/etc/mongod.conf</div><div class="line">systemLog:</div><div class="line">  destination: file</div><div class="line">  path: /usr/<span class="built_in">local</span>/var/<span class="built_in">log</span>/mongodb/mongo.log</div><div class="line">  logAppend: <span class="literal">true</span></div><div class="line">storage:</div><div class="line">  dbPath: /usr/<span class="built_in">local</span>/var/mongodb</div><div class="line">net:</div><div class="line">  bindIp: 127.0.0.1</div></pre></td></tr></table></figure>
<h2 id="MongoDB使用"><a href="#MongoDB使用" class="headerlink" title="MongoDB使用"></a>MongoDB使用</h2><p>我这里就简单开启一个MongoDB服务，直接调用<code>brew services start mongodb</code>就行了，这样MongoDB就启动了。</p>
<p>使用<code>mongo</code>命令即可进入MongoDB控制台。</p>
<p><img src="http://upload-images.jianshu.io/upload_images/1520343-acd14283311d877c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt=""></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line">show dbs                     show database names</div><div class="line">show collections             show collections <span class="keyword">in</span> current database</div><div class="line">show users                   show users <span class="keyword">in</span> current database</div><div class="line">show profile                 show most recent system.profile entries with time &gt;= 1ms</div><div class="line">show logs                    show the accessible logger names</div><div class="line">show <span class="built_in">log</span> [name]              prints out the last segment of <span class="built_in">log</span> <span class="keyword">in</span> memory, <span class="string">'global'</span> is default</div><div class="line">use &lt;db_name&gt;                <span class="built_in">set</span> current database</div><div class="line">db.foo.find()                list objects <span class="keyword">in</span> collection foo</div></pre></td></tr></table></figure>
<p>下面简单演示数据库的增删改查，具体用法请参考<a href="https://docs.mongodb.com/manual/crud/" target="_blank" rel="external">官方CRUD文档</a>。</p>
<p>创建一个<code>abc123</code>的database</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">use abc123</div></pre></td></tr></table></figure>
<p>创建一个<code>user</code>的collection，并插入两条数据。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">&gt; db.user.insert(&#123;name:<span class="string">'aaa'</span>&#125;)</div><div class="line">WriteResult(&#123; <span class="string">"nInserted"</span> : 1 &#125;)</div><div class="line"></div><div class="line">&gt; db.user.insert(&#123;name:<span class="string">'bbb'</span>,age:22&#125;)</div><div class="line">WriteResult(&#123; <span class="string">"nInserted"</span> : 1 &#125;)</div></pre></td></tr></table></figure>
<p>查看<code>user</code>中的数据</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">&gt; db.user.find()</div><div class="line">&#123; <span class="string">"_id"</span> : ObjectId(<span class="string">"59bf7bde5d6768f6ee06de2b"</span>), <span class="string">"name"</span> : <span class="string">"aaa"</span> &#125;</div><div class="line">&#123; <span class="string">"_id"</span> : ObjectId(<span class="string">"59bf7d045d6768f6ee06de2c"</span>), <span class="string">"name"</span> : <span class="string">"bbb"</span>, <span class="string">"age"</span> : 22 &#125;</div></pre></td></tr></table></figure>
<p>根据条件查询</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">&gt; db.user.find(&#123;name:<span class="string">'bbb'</span>&#125;)</div><div class="line">&#123; <span class="string">"_id"</span> : ObjectId(<span class="string">"59bf7d045d6768f6ee06de2c"</span>), <span class="string">"name"</span> : <span class="string">"bbb"</span>, <span class="string">"age"</span> : 22 &#125;</div></pre></td></tr></table></figure>
<p>修改数据</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">&gt; db.user.updateOne(&#123;name:<span class="string">'aaa'</span>&#125;,&#123;<span class="variable">$set</span>:&#123;age:11&#125;&#125;)</div><div class="line">&#123; <span class="string">"acknowledged"</span> : <span class="literal">true</span>, <span class="string">"matchedCount"</span> : 1, <span class="string">"modifiedCount"</span> : 1 &#125;</div><div class="line"></div><div class="line">&gt; db.user.find();</div><div class="line">&#123; <span class="string">"_id"</span> : ObjectId(<span class="string">"59bf7bde5d6768f6ee06de2b"</span>), <span class="string">"name"</span> : <span class="string">"aaa"</span>, <span class="string">"age"</span> : 11 &#125;</div><div class="line">&#123; <span class="string">"_id"</span> : ObjectId(<span class="string">"59bf7d045d6768f6ee06de2c"</span>), <span class="string">"name"</span> : <span class="string">"bbb"</span>, <span class="string">"age"</span> : 22 &#125;</div></pre></td></tr></table></figure>
<p>删除数据</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">&gt; db.user.deleteMany(&#123;name:<span class="string">'aaa'</span>&#125;)</div><div class="line">&#123; <span class="string">"acknowledged"</span> : <span class="literal">true</span>, <span class="string">"deletedCount"</span> : 1 &#125;</div><div class="line"></div><div class="line">&gt; db.user.find()</div><div class="line">&#123; <span class="string">"_id"</span> : ObjectId(<span class="string">"59bf7d045d6768f6ee06de2c"</span>), <span class="string">"name"</span> : <span class="string">"bbb"</span>, <span class="string">"age"</span> : 22 &#125;</div></pre></td></tr></table></figure>
<p>刚刚开始说过，Mongo的数据结构是类似于json的数据结构，数据里面的”_id”就是主键，是系统自己生成的。</p>
<p>当然也可以自己指定，在插入数据的时候，指定”_id”字段即可。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div></pre></td><td class="code"><pre><div class="line">&gt; db.user.insert(&#123;<span class="string">"_id"</span>:<span class="string">"12345"</span>,name:<span class="string">"Hello"</span>&#125;)</div><div class="line">WriteResult(&#123; <span class="string">"nInserted"</span> : 1 &#125;)</div><div class="line"></div><div class="line">&gt; db.user.find()</div><div class="line">&#123; <span class="string">"_id"</span> : ObjectId(<span class="string">"59bf7d045d6768f6ee06de2c"</span>), <span class="string">"name"</span> : <span class="string">"bbb"</span>, <span class="string">"age"</span> : 22 &#125;</div><div class="line">&#123; <span class="string">"_id"</span> : <span class="string">"12345"</span>, <span class="string">"name"</span> : <span class="string">"Hello"</span> &#125;</div><div class="line"></div><div class="line">&gt; db.user.insert(&#123;<span class="string">"_id"</span>:<span class="string">"12345"</span>,name:<span class="string">"Hello"</span>&#125;)</div><div class="line">WriteResult(&#123;</div><div class="line">	<span class="string">"nInserted"</span> : 0,</div><div class="line">	<span class="string">"writeError"</span> : &#123;</div><div class="line">		<span class="string">"code"</span> : 11000,</div><div class="line">		<span class="string">"errmsg"</span> : <span class="string">"E11000 duplicate key error collection: abc123.user index: _id_ dup key: &#123; : \"12345\" &#125;"</span></div><div class="line">	&#125;</div><div class="line">&#125;)</div></pre></td></tr></table></figure>
<p>上面示例表示，第一次插入数据的时候，是成功的，查询结果也是符合预期，当再次执行的时候，插入失败，说明主键冲突。</p>
<h3 id="MongoDB可视化工具"><a href="#MongoDB可视化工具" class="headerlink" title="MongoDB可视化工具"></a>MongoDB可视化工具</h3><p>上面使用的是命令行工具查看数据，可能对有些同学不是很优化，我在这里推荐一款可视化功工具<a href="http://blog.robomongo.org/" target="_blank" rel="external">Robo 3T</a></p>
<p>用Robo 3T查看数据就很方便了。</p>
<p><img src="http://upload-images.jianshu.io/upload_images/1520343-2988a2e07e9d3743.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt=""></p>
<h2 id="Java操作MongoDB"><a href="#Java操作MongoDB" class="headerlink" title="Java操作MongoDB"></a>Java操作MongoDB</h2><p>Java操作Mongo比较简单，直接调用MongoDB的驱动即可，其他部分基本上和上面的语法一样。</p>
<p>本次使用的版本是<code>3.5.0</code>，下面是依赖方式。</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line"><span class="tag">&lt;<span class="name">dependencies</span>&gt;</span></div><div class="line">    <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></div><div class="line">        <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.mongodb<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></div><div class="line">        <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>mongodb-driver<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></div><div class="line">        <span class="tag">&lt;<span class="name">version</span>&gt;</span>3.5.0<span class="tag">&lt;/<span class="name">version</span>&gt;</span></div><div class="line">    <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></div><div class="line"><span class="tag">&lt;/<span class="name">dependencies</span>&gt;</span></div></pre></td></tr></table></figure>
<figure class="highlight groovy"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">dependencies &#123;</div><div class="line">  compile <span class="string">'org.mongodb:mongodb-driver:3.5.0'</span></div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>数据库连接</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">private</span> MongoClient client;</div><div class="line"></div><div class="line"><span class="meta">@Before</span></div><div class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">before</span><span class="params">()</span> </span>&#123;</div><div class="line">    String url = <span class="string">"mongodb://127.0.0.1:27017/abc123"</span>;</div><div class="line">    MongoClientURI uri = <span class="keyword">new</span> MongoClientURI(url);</div><div class="line">    client = <span class="keyword">new</span> MongoClient(uri);</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>查询数据</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div></pre></td><td class="code"><pre><div class="line"><span class="meta">@Test</span></div><div class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">testFind</span><span class="params">()</span> </span>&#123;</div><div class="line">    MongoDatabase database = client.getDatabase(<span class="string">"abc123"</span>);</div><div class="line">    MongoCollection&lt;Document&gt; collection = database.getCollection(<span class="string">"user"</span>);</div><div class="line"></div><div class="line">    <span class="keyword">for</span> (Document document : collection.find()) &#123;</div><div class="line">        <span class="keyword">for</span> (Map.Entry&lt;String, Object&gt; entry : document.entrySet()) &#123;</div><div class="line">            System.out.print(entry.getKey() + <span class="string">":"</span> + entry.getValue() + <span class="string">"\t"</span>);</div><div class="line">        &#125;</div><div class="line">        System.out.println();</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>根据先前的数据，查到的结果2条。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">_id:59bf7d045d6768f6ee06de2c	name:bbb	age:22.0</div><div class="line">_id:12345	name:Hello</div></pre></td></tr></table></figure>
<p>添加数据</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line"><span class="meta">@Test</span></div><div class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">testInsert</span><span class="params">()</span> </span>&#123;</div><div class="line">    testFind();</div><div class="line"></div><div class="line">    MongoDatabase database = client.getDatabase(<span class="string">"abc123"</span>);</div><div class="line">    MongoCollection&lt;Document&gt; collection = database.getCollection(<span class="string">"user"</span>);</div><div class="line">    Document document = <span class="keyword">new</span> Document();</div><div class="line">    document.put(<span class="string">"name"</span>, <span class="string">"World"</span>);</div><div class="line">    document.put(<span class="string">"age"</span>, <span class="number">33</span>);</div><div class="line">    collection.insertOne(document);</div><div class="line"></div><div class="line">    testFind();</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>插入前总共为2条数据，插入后为3条数据。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">_id:59bf7d045d6768f6ee06de2c	name:bbb	age:22.0</div><div class="line">_id:12345	name:Hello</div><div class="line"></div><div class="line">_id:59bf7d045d6768f6ee06de2c	name:bbb	age:22.0</div><div class="line">_id:12345	name:Hello</div><div class="line">_id:59bf8282fe37ad04a81fd012	name:World	age:33</div></pre></td></tr></table></figure>
<p>修改数据</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div></pre></td><td class="code"><pre><div class="line"><span class="meta">@Test</span></div><div class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">testUpdate</span><span class="params">()</span> </span>&#123;</div><div class="line">    System.out.println(<span class="string">"before update"</span>);</div><div class="line">    testFind();</div><div class="line"></div><div class="line">    MongoDatabase database = client.getDatabase(<span class="string">"abc123"</span>);</div><div class="line">    MongoCollection&lt;Document&gt; collection = database.getCollection(<span class="string">"user"</span>);</div><div class="line">    collection.updateMany(</div><div class="line">            Filters.eq(<span class="string">"name"</span>, <span class="string">"World"</span>),</div><div class="line">            Updates.set(<span class="string">"age"</span>, <span class="number">44</span>)</div><div class="line">    );</div><div class="line"></div><div class="line">    System.out.println();</div><div class="line">    System.out.println();</div><div class="line">    System.out.println(<span class="string">"after update"</span>);</div><div class="line">    testFind();</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>修改数据和其他的不一样，<code>collection.updateMany</code>有2个参数，第一个参数<code>Filters.eq(&quot;name&quot;, &quot;World&quot;)</code>是查询条件，第二个参数<code>Updates.set(&quot;age&quot;, 44)</code>为赋值语句。</p>
<p>在修改前数据为<code>_id:59bf8282fe37ad04a81fd012    name:World    age:33</code>，修改后就变成了<code>_id:59bf8282fe37ad04a81fd012    name:World    age:44</code>。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line">before update</div><div class="line">_id:59bf7d045d6768f6ee06de2c	name:bbb	age:22.0</div><div class="line">_id:12345	name:Hello</div><div class="line">_id:59bf8282fe37ad04a81fd012	name:World	age:33</div><div class="line"></div><div class="line"></div><div class="line">after update</div><div class="line">_id:59bf7d045d6768f6ee06de2c	name:bbb	age:22.0</div><div class="line">_id:12345	name:Hello</div><div class="line">_id:59bf8282fe37ad04a81fd012	name:World	age:44</div></pre></td></tr></table></figure>
<p>删除数据</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div></pre></td><td class="code"><pre><div class="line"></div><div class="line"><span class="meta">@Test</span></div><div class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">testDelete</span><span class="params">()</span> </span>&#123;</div><div class="line">    System.out.println(<span class="string">"before delete"</span>);</div><div class="line">    testFind();</div><div class="line"></div><div class="line">    MongoDatabase database = client.getDatabase(<span class="string">"abc123"</span>);</div><div class="line">    MongoCollection&lt;Document&gt; collection = database.getCollection(<span class="string">"user"</span>);</div><div class="line">    collection.deleteMany(</div><div class="line">            Filters.eq(<span class="string">"name"</span>, <span class="string">"World"</span>)</div><div class="line">    );</div><div class="line"></div><div class="line">    System.out.println();</div><div class="line">    System.out.println();</div><div class="line">    System.out.println(<span class="string">"after delete"</span>);</div><div class="line">    testFind();</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>删除前有三条数据，删除后只有2条数据。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">before delete</div><div class="line">_id:59bf7d045d6768f6ee06de2c	name:bbb	age:22.0</div><div class="line">_id:12345	name:Hello</div><div class="line">_id:59bf8282fe37ad04a81fd012	name:World	age:44</div><div class="line"></div><div class="line"></div><div class="line">after delete</div><div class="line">_id:59bf7d045d6768f6ee06de2c	name:bbb	age:22.0</div><div class="line">_id:12345	name:Hello</div></pre></td></tr></table></figure>
<h2 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h2><p>总的来说，MongoDB使用还是很简单的，相对于传统的关系型数据库，优缺点表现如下。</p>
<p><strong>优点:</strong></p>
<ul>
<li><p>面向文档存储(类JSON数据模式简单而强大)</p>
</li>
<li><p>动态查询</p>
</li>
<li><p>全索引支持,扩展到内部对象和内嵌数组</p>
</li>
<li><p>查询记录分析</p>
</li>
<li><p>快速,就地更新</p>
</li>
<li><p>高效存储二进制大对象 (比如照片和视频)</p>
</li>
<li><p>复制和故障切换支持</p>
</li>
<li><p>Auto- Sharding自动分片支持云级扩展性</p>
</li>
<li><p>MapReduce 支持复杂聚合</p>
</li>
<li><p>商业支持,培训和咨询</p>
</li>
</ul>
<p><strong>缺点:</strong></p>
<ul>
<li><p>不支持事务（进行开发时需要注意，哪些功能需要使用数据库提供的事务支持）</p>
</li>
<li><p>MongoDB占用空间过大 （不过这个确定对于目前快速下跌的硬盘价格来说，也不算什么缺点了）</p>
</li>
<li><p>MongoDB没有如MySQL那样成熟的维护工具，这对于开发和IT运营都是个值得注意的地方</p>
</li>
<li><p>在32位系统上，不支持大于2.5G的数据(很多操作系统都已经抛弃了32位版本，所以这个也算不上什么缺点了，3.4版本已经放弃支持32 位 x86平台)</p>
</li>
</ul>
<h2 id="相关资料"><a href="#相关资料" class="headerlink" title="相关资料"></a>相关资料</h2><p><a href="https://www.mongodb.com/" target="_blank" rel="external">MongoDB的官网</a></p>
<p><a href="https://brew.sh/" target="_blank" rel="external">Homebrew</a></p>
<p><a href="https://docs.mongodb.com/manual/crud/" target="_blank" rel="external">官方CRUD文档</a></p>
<p><a href="http://blog.robomongo.org/" target="_blank" rel="external">Robo 3T</a></p>
<p><a href="http://blog.csdn.net/zdc524/article/details/46967413" target="_blank" rel="external">MongoDB 的优点和缺点</a></p>

      
    </div>
    
    
    

    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>坚持原创技术分享，您的支持将鼓励我继续创作！</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/images/wechat_pay.jpeg" alt="流水不腐小夏 微信支付"/>
        <p>微信支付</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/images/alipay.jpeg" alt="流水不腐小夏 支付宝"/>
        <p>支付宝</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/MongoDB/" rel="tag"># MongoDB</a>
          
            <a href="/tags/Java-MongoDB/" rel="tag"># Java MongoDB</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/09/21/Curl-S/" rel="next" title="Curl不显示统计信息% Total % Received %">
                <i class="fa fa-chevron-left"></i> Curl不显示统计信息% Total % Received %
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/10/13/MyMockServer/" rel="prev" title="使用MyMockServer模拟数据">
                使用MyMockServer模拟数据 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
      <div id="disqus_thread">
        <noscript>
          Please enable JavaScript to view the
          <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a>
        </noscript>
      </div>
    </div>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/images/avatar.jpeg"
                alt="流水不腐小夏" />
            
              <p class="site-author-name" itemprop="name">流水不腐小夏</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">31</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">10</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">55</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          
            <div class="feed-link motion-element">
              <a href="/atom.xml" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
            </div>
          

          <div class="links-of-author motion-element">
            
              
                <span class="links-of-author-item">
                  <a href="https://github.com/LiushuiXiaoxia" target="_blank" title="GitHub">
                    
                      <i class="fa fa-fw fa-GitHub"></i>GitHub</a>
                </span>
              
                <span class="links-of-author-item">
                  <a href="http://www.jianshu.com/u/58771f980bac" target="_blank" title="简书">
                    
                      <i class="fa fa-fw fa-简书"></i>简书</a>
                </span>
              
                <span class="links-of-author-item">
                  <a href="http://blog.csdn.net/guijiaoba" target="_blank" title="CSDN">
                    
                      <i class="fa fa-fw fa-CSDN"></i>CSDN</a>
                </span>
              
            
          </div>

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#浅谈MongoDB数据库"><span class="nav-number">1.</span> <span class="nav-text">浅谈MongoDB数据库</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#简介"><span class="nav-number">1.1.</span> <span class="nav-text">简介</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#MongoDB-介绍"><span class="nav-number">1.2.</span> <span class="nav-text">MongoDB 介绍</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#数据库安装"><span class="nav-number">1.2.1.</span> <span class="nav-text">数据库安装</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#MongoDB使用"><span class="nav-number">1.3.</span> <span class="nav-text">MongoDB使用</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#MongoDB可视化工具"><span class="nav-number">1.3.1.</span> <span class="nav-text">MongoDB可视化工具</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Java操作MongoDB"><span class="nav-number">1.4.</span> <span class="nav-text">Java操作MongoDB</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#总结"><span class="nav-number">1.5.</span> <span class="nav-text">总结</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#相关资料"><span class="nav-number">1.6.</span> <span class="nav-text">相关资料</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; 2015 &mdash; <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">流水不腐小夏</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.3</div>




        
<div class="busuanzi-count">
  <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  

  
</div>








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.3"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.3"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.3"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.3"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.3"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.3"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.3"></script>



  


  

    
      <script id="dsq-count-scr" src="https://mycommons-cn.disqus.com/count.js" async></script>
    

    
      <script type="text/javascript">
        var disqus_config = function () {
          this.page.url = 'http://mycommons.cn/2017/09/28/MongoDb/';
          this.page.identifier = '2017/09/28/MongoDb/';
          this.page.title = '浅谈MongoDB数据库';
        };
        var d = document, s = d.createElement('script');
        s.src = 'https://mycommons-cn.disqus.com/embed.js';
        s.setAttribute('data-timestamp', '' + +new Date());
        (d.head || d.body).appendChild(s);
      </script>
    

  




	





  














  




  
  
  
  <link rel="stylesheet" href="/lib/algolia-instant-search/instantsearch.min.css">

  
  
  <script src="/lib/algolia-instant-search/instantsearch.min.js"></script>
  

  <script src="/js/src/algolia-search.js?v=5.1.3"></script>



  

  

  
  

  
  
    <script type="text/x-mathjax-config">
      MathJax.Hub.Config({
        tex2jax: {
          inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
          processEscapes: true,
          skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
        }
      });
    </script>

    <script type="text/x-mathjax-config">
      MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax(), i;
        for (i=0; i < all.length; i += 1) {
          all[i].SourceElement().parentNode.className += ' has-jax';
        }
      });
    </script>
    <script type="text/javascript" src="//cdn.bootcss.com/mathjax/2.7.1/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
  


  

  

</body>
</html>
